<?php 
$query_lo = sprintf("SELECT * FROM learning_outcomes WHERE cid='%s' AND del_num='%s'", $cid, $row_view_specific['del_num']);
$lo = mysql_query($query_lo, $connection) or die(mysql_error());
$row_lo = mysql_fetch_assoc($lo);
$totalRows_lo = mysql_num_rows($lo);

$query_cpd_latest = sprintf("SELECT * FROM $dbTable WHERE cid='$cid' AND del_num='%s' ORDER BY vid DESC", $row_view_specific['del_num']); 
$cpd_latest = mysql_query($query_cpd_latest, $connection) or die(mysql_error());
$row_cpd_latest = mysql_fetch_assoc($cpd_latest);
$totalRows_cpd_latest = mysql_num_rows($cpd_latest);

if (($section == "comments") || ($section == "view_comments")) { ?>
<div id="comment-preview">
<h2><?php echo "Deliverable ".$row_view_specific['del_num']." &mdash; ".$row_view_specific['pd_name']; ?></h2>
<table class="dataTable">
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Applies To</td>
    <td class="data">Module <?php echo $row_view_specific['mid']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Weekly Project Deliverable</td>
    <td class="data"><?php echo $row_view_specific['pd_desc1']; ?></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">  
    <td class="dataLabel">What Students Need to Know</td>
    <td class="data"><?php echo $row_view_specific['pd_desc2']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Information Covered in Themes</td>
    <td class="data"><?php echo $row_view_specific['pd_desc3']; ?></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
    <td class="dataLabel">Information Covered in Readings</td>
    <td class="data"><?php echo $row_view_specific['pd_desc4']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Topics Discussed in Forum</td>
    <td class="data"><?php echo $row_view_specific['pd_desc5']; ?></td>
</tr>
</table>
<h2>Associated Learning Outcomes</h2>
<table class="dataTable">
<tr>
	<th>Upon successful completion of this course, each student will be able to...</th>
    <?php if ($row_user['userLevel'] <= "2") { ?>
    <th width="1%">&nbsp;</th>
    <?php } ?>
</tr>
<?php do { ?>
<tr style="background-color: <?php echo $color; ?>">
	<td><?php echo $row_lo['lo_text']; ?></td>
    <?php if ($row_user['userLevel'] <= "2") { ?>
    <td nowrap="nowrap"><div class="stacked"><span class="icon"><img src="images/comment_add.png" align="absmiddle" border="0"></span><a href="index.php?section=comments&action=add&cid=<?php echo $cid; ?>&amp;dbTable=learning_outcomes&amp;id=<?php echo $row_lo['id']; ?>&amp;modal_window=<?php echo $modal_window; ?>">Add Comment</a></div></td>
    <?php } ?>

</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_lo = mysql_fetch_assoc($lo)); ?>
</table>
</div>

<?php } // END if (($section == "comments") || ($section == "view_comments"))
else {
if (($row_cpd_latest['vid'] == $row_view_specific['vid']) && ($totalRows_comments > 0)) { 
 	if ($row_comments['changes'] == "Y") echo "<div class='error_msg'>Changes are needed to this course project deliverable.";
	if ($row_user['userLevel'] >= "2") echo " <a href='index.php?section=proj_deliv&action=edit&go=".$go."&amp;view=proposal_detail&cid=".$cid."&id=".$row_comments['rid']."&amp;modal_window=".$modal_window."'>Make Changes?</a>"; 
?>
<h2>Course Project Deliverable  <?php if (($id != "default") && ($row_user['userLevel'] <= "2")) echo " (Version ".$row_view_specific['vid'].")"; ?></h2>
<?php if (($row_user['userLevel'] <= "2") && ($section != "comments") && ($row_cpd_latest['vid'] == $row_view_specific['vid'])) echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a href='index.php?section=comments&action=add&cid=".$cid."&dbTable=project_deliverable&id=".$row_view_specific['id']."&amp;modal_window=".$modal_window."'>Add Comment</a></div>"; ?>
<?php } ?>
<table class="dataTable">
<tr>
	<th colspan="2"><?php echo "Deliverable ".$row_view_specific['del_num']." &mdash; ".$row_view_specific['pd_name']; ?></th>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Applies To</td>
    <td class="data">Module <?php echo $row_view_specific['mid']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Weekly Project Deliverable</td>
    <td class="data"><?php echo $row_view_specific['pd_desc1']; ?></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">  
    <td class="dataLabel">What Students Need to Know</td>
    <td class="data"><?php echo $row_view_specific['pd_desc2']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Information Covered in Themes</td>
    <td class="data"><?php echo $row_view_specific['pd_desc3']; ?></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
    <td class="dataLabel">Information Covered in Readings</td>
    <td class="data"><?php echo $row_view_specific['pd_desc4']; ?></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    <td class="dataLabel">Topics Discussed in Forum</td>
    <td class="data"><?php echo $row_view_specific['pd_desc5']; ?></td>
</tr>
</table>
<?php if ($totalRows_lo > 0) { ?>
<a name="lo"></a><h2>Associated Learning Outcomes</h2>
<table class="dataTable">
<tr>
	<th>Upon successful completion of this course, each student will be able to...</th>
     <?php if (($row_user['userLevel'] <= "2")  && ($section != "comments")) { ?>
    <th width="1%">&nbsp;</th>
    <?php } ?>
</tr>
<?php do { ?>
<tr style="background-color: <?php echo $color; ?>">
	<td><?php echo $row_lo['lo_text']; ?></td>
    <?php if (($row_user['userLevel'] <= "2")  && ($section != "comments")) { ?>
    <td nowrap="nowrap"><div class="stacked"><span class="icon"><img src="images/comment_add.png" align="absmiddle" border="0"></span><a href="index.php?section=comments&action=add&cid=<?php echo $cid; ?>&amp;dbTable=learning_outcomes&amp;id=<?php echo $row_lo['id']; ?>&amp;modal_window=<?php echo $modal_window; ?>">Add Comment</a></div></td>
    <?php } ?>

</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_lo = mysql_fetch_assoc($lo)); ?>
</table>
<?php } ?>
<?php if ($totalRows_comments > 0) { ?>
<a name="comments"></a><h2>ID Comments</h2>
<table class="dataTable">
<tr>
	<th width="10%" nowrap="nowrap">Instructional Designer</th>
    <th>Comments</th>
    <th width="13%">Changes Needed?</th>
    <th width="13%"></th>
</tr>
<?php do { ?>
<tr style="background-color: <?php echo $color; ?>">
	<td width="5%" nowrap="nowrap"><p><?php echo $row_id['firstName']." ".$row_id['lastName']; ?><p></td>
    <td class="data"><?php echo $row_comments['comment']; ?></td>
    <td class="data"><?php if (($row_cpd_latest['vid'] == $row_view_specific['vid'])) { if ($row_comments['changes'] == "Y") echo "<span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; else echo "<span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No"; } else echo "Version out of date."; ?>
    <td class="data">
	<?php if (($row_cpd_latest['vid'] == $row_view_specific['vid']) && ($row_comments['changes'] == "Y") && ($row_user['userLevel'] >= "2"))  echo "<a href='index.php?section=proj_deliv&action=edit&go=".$go."&amp;view=proposal_detail&cid=".$cid."&id=".$row_comments['rid']."&amp;modal_window=".$modal_window."'>Make Changes</a>"; else echo ""; ?>
    </td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_comments = mysql_fetch_assoc($comments)); ?>
</table>
<?php } 
} ?>